local function main (userOb, msgData)
    local weapon = INVENTORY_D:find_weapon_by_purchase(userOb)
    if not weapon then
        local result = {}
        result.code = 400
        userOb:send_packet("MSGS2CBuyWeapons", result)
        return
    end

    if msgData.id ~= weapon.id then
        local result = {}
        result.code = 401
        userOb:send_packet("MSGS2CBuyWeapons", result)
        return
    end

    local pos = INVENTORY_D:get_inv_idle_pos(userOb)
    if not pos then
        local result = {}
        result.code = 402
        userOb:send_packet("MSGS2CBuyWeapons", result)
        return
    end

    local item_price_value = weapon.coinPurchase
    if msgData.isbuff and msgData.isbuff > 0 then
        item_price_value = item_price_value / 2
    end

    local currency = userOb:get_currency(GamePropIds.kGamePropIdsCopperIcon)
    if currency < item_price_value then
        local result = {}
        result.code = 403
        result.origin_item = INVENTORY_D:get_currency_show_count(userOb, GamePropIds.kGamePropIdsCopperIcon, currency)
        result.item = INVENTORY_D:get_currency_show_count(userOb, GamePropIds.kGamePropIdsCopperIcon, item_price_value)
        result.max_rank = max_rank
        userOb:send_packet("MSGS2CBuyWeapons", result)
        return
    end

    --扣除道具
    INVENTORY_D:cost_currency(userOb, GamePropIds.kGamePropIdsCopperIcon, item_price_value)

    --增加新装备
    userOb:add_prop(weapon.id)

    --增加幸运值
    local luckey = userOb:set("critup_luck", (userOb:query("critup_luck") or 0) + 1)

    local result = {}
    result.code = 200
    result.luckey = luckey
    result.id = weapon.id
    result.pops = pos
    result.isbuff = msgData.isbuff
    userOb:send_packet("MSGS2CBuyWeapons", result)
    ITEM_D:send_currency_info(userOb)
    ITEM_D:send_props_info(userOb)
end

--注册方法
COMMAND_D:register_command("MSGC2SBuyWeapons",GameCmdType.NONE, main)
